package com.zy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.domain.User;
import com.zy.mapper.UserMapper;
import com.zy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserService userService;

    @Override
    public User findByOpenid(String openid) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getOpenid,openid);
        return userService.getOne(queryWrapper);
    }

    @Override
    public void insert(User user) {
        userService.save(user);
    }

    @Override
    public void updateScore(User user) {
        User temp = userService.findByOpenid(user.getOpenid());
        if (temp.getTopScore() < user.getTopScore()) {
            temp.setTopScore(user.getTopScore());
            userService.updateById(temp);
        }
    }
}
